<%--
  Created by IntelliJ IDEA.
  User: jackiechan
  Date: 20-7-28
  Time: 上午10:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>

    <script type="text/javascript">
        function WebSocketTest() {
            if ("WebSocket" in window) {
                alert("您的浏览器支持 WebSocket!");

                // 打开一个 web socket
                var ws = new WebSocket("ws://tomcat02.qfjava.cn:81/websocket/websocket/${oid}");

                ws.onopen = function () {
                    // Web Socket 已连接上，使用 send() 方法发送数据
                    ws.send("发送数据");
                    // alert("数据发送中...");
                    setContent('链接成功');
                };

                ws.onmessage = function (evt) {
                    var received_msg = evt.data;
                    //  alert("数据已接收...");
                    setContent(received_msg);
                    if (received_msg == '1') {
                        location.href = "http://localhost:8080"
                    }
                };

                ws.onclose = function () {
                    // 关闭 websocket
                    // alert("连接已关闭...");
                    setContent('关闭链接');
                };
            } else {
                // 浏览器不支持 WebSocket
                alert("您的浏览器不支持 WebSocket!");
            }
        }

        function setContent(data) {
            document.getElementById("content").innerHTML = data;
        }
    </script>
</head>
<body onload="WebSocketTest()">
订单号:${oid}<br>
商品名称:${title}<br>
扫码支付:<br>
<br>
<br>
<br>
<br>
<img src="image/${oid}">
<br>
<br>
<br>
<br>
<span id="content"></span>
</body>
</html>
